package com.gdk.ksoft.ui.works.adapters;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gdk.ksoft.R;
import com.gdk.ksoft.data.entry.tables.OneGoodsTypesTable;

import java.util.List;

/**
 * Created by hel on 2014-12-17.
 * 商品同品多味数据填充适配器
 */
public class GoodsTpdwAdapter extends BaseAdapter {

    private Context context;
    private List<OneGoodsTypesTable> list;

    public GoodsTpdwAdapter(Context context, List<OneGoodsTypesTable> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView txtView = new TextView(context);
        txtView.setTextSize(TypedValue.COMPLEX_UNIT_DIP,18f);
        txtView.setText(list.get(position).mc);
        txtView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        txtView.setPadding(20, 15, 10, 15);
        txtView.setBackgroundResource(R.drawable.selector_goodsbrand_bg);
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                AbsListView.LayoutParams.MATCH_PARENT,
                AbsListView.LayoutParams.WRAP_CONTENT);
        Drawable arrowRight = context.getResources().getDrawable(R.drawable.ic_arrow_right);
        arrowRight.setBounds(0,0,arrowRight.getIntrinsicWidth(),arrowRight.getIntrinsicHeight());
        txtView.setCompoundDrawables(null, null, arrowRight, null);
        txtView.setCompoundDrawablePadding(10);
        txtView.setLayoutParams(lp);
        return txtView;
    }

    /**
     * 获取数据源
     * @return
     */
    public List<OneGoodsTypesTable> getSourceList(){
        return this.list;
    }
}
